//
//  MainTabBarController.swift
//  WBPoject
//
//  Created by WorkSpace on 15/10/18.
//  Copyright © 2015年 商刻. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {
    @IBOutlet weak var mainTabBar: MainTabBar!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        addChildViewControllers();
        
        mainTabBar.composedButton.addTarget(self, action:"composedButtonClicked" , forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    func composedButtonClicked(){
        
        print("\(__FUNCTION__)", terminator: "")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    private func addChildViewControllers() {
        
        tabBar.tintColor = UIColor.orangeColor()
        
        addOneChildViewController("Home", "首页", "tabbar_home")
        addOneChildViewController("Message", "消息", "tabbar_message_center")
        addOneChildViewController("Discover", "发现", "tabbar_discover")
        addOneChildViewController("Profile", "我", "tabbar_profile")
        
    }
    
    private func addOneChildViewController(sbName :String ,_ title : String ,_ imageName :String) {
        
        let sb = UIStoryboard(name: sbName, bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
//        nav.title = title
        nav.topViewController?.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.image = UIImage(named: imageName + "_highlighted")
        
        addChildViewController(nav)
        
    }
}
